import Vue from 'vue';
import Router from 'vue-router';
import layout from '@/views/layout';

import MyAfterSales from '../views/orderDetail/MyAfterSales.vue'
import MyOrderSubsystem from '../views/orderDetail/MyOrderSubsystem.vue'
import OrderDetalis from '../views/orderDetail/OrderDetalis.vue'
import OrderDetalis1 from '../views/orderDetail/OrderDetalis1.vue'
import OrderDetalisIndividual from '../views/orderDetail/OrderDetalisIndividual.vue'
import OrderDetalisFabric from '../views/orderDetail/OrderDetalisFabric.vue'
import OrderDetalisGroup from '../views/orderDetail/OrderDetalisGroup.vue'
import OrderDetalisSpotGoods from '../views/orderDetail/OrderDetalisSpotGoods.vue'
import AfterSaleGeding from '../views/orderDetail/AfterSaleGeding.vue'
import AfterSaleFabric from '../views/orderDetail/AfterSaleFabric.vue'
import AfterSaleGroup from '../views/orderDetail/AfterSaleGroup.vue'
import CustomizesInfo from '../views/orderDetail/CustomizesInfo.vue'
import CustomizesClothesInfo from '../views/orderDetail/CustomizesClothesInfo.vue'
import DeppDetail from "../views/orderDetail/DeppDetail";
import UndeliveredPersonnelList from '../views/orderDetail/UndeliveredPersonnelList.vue'
import PiciPerson2 from '../views/orderDetail/PiciPerson2'
import NewAfterSaleOrder1 from '../views/orderDetail/NewAfterSaleOrder1.vue'
import NewAfterSaleOrder2 from '../views/orderDetail/NewAfterSaleOrder2.vue'
import NewAfterSaleOrder3 from '../views/orderDetail/NewAfterSaleOrder3.vue'
import NewAfterSaleOrder4 from '../views/orderDetail/NewAfterSaleOrder4.vue'
import teamAfteronepersonDetail from '../views/orderDetail/teamAfteronepersonDetail.vue'
import groupOrder from './group-order';
import OrderDetalisGroup2 from '../views/group-order/OrderDetalisGroup2.vue'
import OrderDetalisGroup3 from '../views/group-order/OrderDetalisGroup3.vue'
import smallMonthList from '../views/game-guide/smallMonthList.vue'

Vue.use(Router)

/**
 * 路由
 * hidden       侧边栏是否隐藏,默认为false
 */
export const urlRouters = [
    {
        path: '/',
        component: layout,
        redirect: '/home',
        children: [
            {path: 'home', name: 'home', component: () => import('@/views/index'), meta: {title: '首页', bread: '首页'}},
        ],
    },
    {
        path: '/login',
        component: () => import('@/views/login'),
        meta: {title: '登录'}
    },
    {
        path: '/order_user',
        component: layout,
        meta: {title: '个定下单'},
        redirect: '/order_user/index',
        children: [
            {path: 'index', component: () => import('@/views/Order_user/index'), meta: {title: '个定下单'}},
            {path: 'view/:oid', component: () => import('@/views/Order_user/viewInfo'), meta: {title: '个定下单'}},
        ]
    },

    // {
    //     path: "/",
    //     name: "Home",
    //     component: () =>
    //         import(/* webpackChunkName: "Home" */ "@/views/home/index.vue"),
    // },
    {
        path: "/game-guide",
        name: "game-guide",
        component: () =>
            import(
                /* webpackChunkName: "game-guide" */ "@/views/game-guide/index.vue"
                ),
        meta: {
            title: "我的账户",
        },
    },
    {
        path: "/my-repair",
        name: "my-repair",
        component: () =>
            import(/* webpackChunkName: "my-repair" */ "@/views/my-repair/index.vue"),
        meta: {
            title: "我的返修",
        },
    },
    {
        path: "/new-repair",
        name: "new-repair",
        component: () =>
            import(
                /* webpackChunkName: "new-repair" */ "@/views/new-repair/index.vue"
                ),
        meta: {
            title: "我的返修",
        },
    },
    {
        path: "/my-order",
        name: "my-order",
        // component: MyOrderSubsystem,
        component: () =>
            import(/* webpackChunkName: "my-order" */ "@/views/my-order/index.vue"),
        meta: {
            title: "我的订单",
        }
    },
    {
        path: "/my-order2",
        name: "my-order2",
        component: MyOrderSubsystem,
        /* component: () =>
             import(/!* webpackChunkName: "my-order" *!/ "@/views/my-order/index.vue"),*/
        meta: {
            title: "我的订单",
        }
    },
    {
        path: "/my-afterordernew",
        name: "my-afterordernew",
        component: MyAfterSales,
        /*component: () =>
            import(/!* webpackChunkName: "my-aferorder" *!/ "@/views/my-afterorder/index.vue"),*/
        meta: {
            title: "我的售后新的",
        },
    },
    {
        path: "/my-afterorder",
        name: "my-afterorder",
        // component: MyAfterSales,
        component: () =>
            import(/* webpackChunkName: "my-aferorder" */ "@/views/my-afterorder/index.vue"),
        meta: {
            title: "我的售后",
        },
    },
    {
        path: "/ask-buy",
        name: "ask-buy",
        component: () =>
            import(/* webpackChunkName: "ask-buy" */ "@/views/ask-buy/index.vue"),
        meta: {
            title: "求购",
        },
    },
    {
        path: "/my-client",
        name: "my-client",
        component: () =>
            import(/* webpackChunkName: "my-client" */ "@/views/my-client/index.vue"),
        meta: {
            title: "我的客户",
        },
    },
    {
        path: "/my-company",
        name: "my-company",
        component: () =>
            import(
                /* webpackChunkName: "my-company" */ "@/views/my-company/index.vue"
                ),
        meta: {
            title: "我的公司",
        },
    },
    {
        path: "/my-statement",
        name: "my-statement",
        component: () =>
            import(
                /* webpackChunkName: "my-statement" */ "@/views/my-statement/index.vue"
                ),
        meta: {
            title: "我的报表",
        },
    },
    {
        path: "/login",
        name: "login",
        meta: {
            // isHeader: true,
        },
        component: () =>
            import(/* webpackChunkName: "login" */ "@/views/login/index.vue"),
    }, {
        // 我的订单界面点击返修(团订返修)
        path: '/orderFan',
        name: "orderFan",
        meta: {
            title: "团订返修"
        },
        component: () => import(/* webpackChunkName: "my-order" */ "@/views/my-order/orderFan.vue")
    }, {
        // 我的订单界面点击返修（个订返修）
        path: '/SingleOrderFan',
        name: "SingleOrderFan",
        meta: {
            title: "个定返修"
        },
        component: () => import(/* webpackChunkName: "my-order" */ "@/views/my-order/SingorderFan.vue")
    },
    {
        path: "/store",
        name: "store",
        meta: {
            keepAlive: true,
            title: "面料下单"
        },
        // component: () => import("./views/store.vue")
        component: () => import("@/views/fabric-downorder/store.vue")
    },
    {
        path: "/materials",
        name: "materials",
        meta: {
            title: "面料下单"
        },
        // component: () => import("./views/materials.vue")
        component: () => import("@/views/fabric-downorder/materials.vue")
    },

    {
        path: "/goodsStore",
        name: "goodsStore",
        meta: {
            keepAlive: true,
            title: "现货下单"
        },
        component: () => import("@/views/my-goods/GoodsStore.vue")
    },

    {
        path: "/goodsmaterials",
        name: "goodsmaterials",
        meta: {
            keepAlive: true,
            title: "现货下单"
        },
        component: () => import("@/views/my-goods/GoodsMaterials.vue")
    },

    {
        path: "/copyMysingleorder",
        name: "copyMysingleorder",
        meta: {
            title: "个定复制订单"
        },
        // component: () => import("./views/materials.vue")
        component: () => import("@/views/Order_user/Singorder-copy.vue")
    },


    {
        path: '/smallMonthList',
        name: 'smallMonthList',
        component: smallMonthList
    },
    {
        path: '/MyAfterSales',
        name: 'MyAfterSales',
        component: MyAfterSales
    },
    {
        path: '/MyOrderSubsystem',
        name: 'MyOrderSubsystem',
        component: MyOrderSubsystem
    },
    {
        path: '/MyOrderSubsystem/OrderDetalis',
        name: 'MyOrderSubsystem',
        component: OrderDetalis
    },
    {
        path: '/MyOrderSubsystem/OrderDetalis1',
        name: 'MyOrderSubsystem',
        component: OrderDetalis1
    },
    {
        path: '/MyOrderSubsystem/OrderDetalisIndividual',
        name: 'MyOrderSubsystem',
        component: OrderDetalisIndividual
    },
    {
        path: '/MyOrderSubsystem/OrderDetalisFabric',
        name: 'MyOrderSubsystem',
        component: OrderDetalisFabric,
        meta: {
            title: '面料订单详情'
        }
    },
    {
        path: '/MyOrderSubsystem/OrderDetalisGroup',
        name: 'MyOrderSubsystem',
        component: OrderDetalisGroup
    },
    {
        path: '/MyOrderSubsystem/OrderDetalisSpotGoods',
        name: 'MyOrderSubsystem',
        component: OrderDetalisSpotGoods
    },
    {
        path: '/MyAfterSales/AfterSaleGeding',
        name: 'MyAfterSales',
        component: AfterSaleGeding
    },
    {
        path: '/MyAfterSales/AfterSaleFabric',
        name: 'MyAfterSales',
        component: AfterSaleFabric
    },
    {
        path: '/MyAfterSales/AfterSaleGroup',
        name: 'MyAfterSales',
        component: AfterSaleGroup
    },
    {
        path: '/MyOrderSubsystem/CustomizesInfo',
        name: 'MyOrderSubsystem',
        component: CustomizesInfo
    },

    {
        path: '/MyOrderSubsystem/CustomizesClothesInfo',
        name: 'MyOrderSubsystem',
        component: CustomizesClothesInfo
    }, {
        path: '/MyOrderSubsystem/DeppDetail',
        name: 'DeppDetail',
        component: DeppDetail
    },
    {
        path: '/MyOrderSubsystem/UndeliveredPersonnelList',
        name: 'MyOrderSubsystem',
        component: UndeliveredPersonnelList
    },
    {
        path: '/MyOrderSubsystem/PiciPerson2', // 批次人员列表
        name: 'MyOrderSubsystem',
        component: PiciPerson2
    },
    {
        path: '/MyOrderSubsystem/NewAfterSaleOrder1',
        name: 'MyOrderSubsystem',
        component: NewAfterSaleOrder1
    }, {
        path: '/MyOrderSubsystem/NewAfterSaleOrder2',
        name: 'MyOrderSubsystem',
        component: NewAfterSaleOrder2
    }, {
        path: '/MyOrderSubsystem/NewAfterSaleOrder3',
        name: 'MyOrderSubsystem',
        component: NewAfterSaleOrder3
    }, {
        path: '/MyOrderSubsystem/NewAfterSaleOrder4',
        name: 'MyOrderSubsystem',
        component: NewAfterSaleOrder4
    },
    //团订售后中，售后人员列表的详情
    {
        path: '/TeamAfterDetail/teamAfteronepersonDetail',
        name: 'teamAfteronepersonDetail',
        component: teamAfteronepersonDetail
    },
    {
        path: '/MyOrderSubsystem/OrderDetalisGroup2',
        name: 'MyOrderSubsystem2',
        component: OrderDetalisGroup2
    },
    {
        path: '/MyOrderSubsystem/OrderDetalisGroup3',
        name: 'MyOrderSubsystem3',
        component: OrderDetalisGroup3
    },

    {
        path: "/my-message",
        name: "my-message",
        component: () =>
            import(
                /* webpackChunkName: "game-guide" */ "@/views/message/index.vue"
                ),
        meta: {
            title: "我的消息",
        },
    },
    {
        path: "/message-detail",
        name: "message-detail",
        component: () =>
            import(
                /* webpackChunkName: "game-guide" */ "@/views/message/MessageDetail.vue"
                ),
        meta: {
            title: "消息详情",
        },
    },

    {
        path: "/xieyi-detail",
        name: "xieyi-detail",
        component: () =>
            import(
                /* webpackChunkName: "game-guide" */ "@/views/message/userxieyi.vue"
                ),
        meta: {
            title: "用户协议",
        },
    },

    {
        path: "/duizhao",
        name: "duizhao",
        component: () =>
            import(
                /* webpackChunkName: "game-guide" */ "@/views/message/contrastDetail.vue"
                ),
        meta: {
            title: "单耗对照表",
        },
    },

    {
        path: "/goods-detail",
        name: "goods-detail",
        component: () =>
            import(
                /* webpackChunkName: "game-guide" */ "@/views/my-goods/GoodsDetail.vue"
                ),
        meta: {
            title: "商品详情",
        },
    },

    {path: '*', redirect: '/home'},
    ...groupOrder
];


const router = new Router({
    mode: 'history',  //去掉url中的#
    routes: urlRouters,
    scrollBehavior: () => ({y: 0})//在切换路由页面时，期望滚动条停留的位置
});

router.beforeEach((to, from, next) => {
    const blackList = ["/login"];
    const isLogin = localStorage.getItem("token");
    // if (to.matched[0].meta.title!=undefined)
    // document.title = to.matched[0].meta.title
    if (blackList.includes(to.path)) {
        next();
    } else {
        if (isLogin) {
            next();
        } else {
            next({
                path: "/login",
                query: {
                    require: to.fullPath,
                },
            });
        }
    }
});

export default router
